/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package dal;

import static banvetauserver.BanVeTauServer.cis;
import static banvetauserver.BanVeTauServer.cos;
import banvetauserver.Serializer;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 *
 * @author Sy Dai
 */
public class connection {

    public connection() {
        this.connect();
    }

    public String connect() {
        try {
            ServerSocket srvSocket = new ServerSocket(10000);
            System.out.println("Waiting...");
            Socket client = srvSocket.accept();
            System.out.println("Have client...");

            cos = new ObjectOutputStream(client.getOutputStream());
            cis = new ObjectInputStream(client.getInputStream());
            System.out.println("Connected to stream...");
            int funcNunber = cis.read();

            if (funcNunber == 1) {
                System.out.println("Function Login");
                byte[] infoBytes = new byte[cis.read()];
                cis.read(infoBytes);
                String[] s = (String[]) Serializer.deserialize(infoBytes);
                System.out.println(s[0] + "," + s[1]);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }

}
